﻿using System.Collections.Generic;
using System.Linq;
using GuRenFang.Service.Entity;
using GuRenFang.Service.IDa;

namespace GuRenFang.Da
{
    public class MessagesRepository :RepositoryBase<Messages> ,IMessagesRepository
    {
        public MessagesRepository(IDatabaseFactory databaseFactory)
            : base(databaseFactory)
         {

         }

        public IEnumerable<Messages> GetItemsByPages(int pageIndex, int pageSize, string orderFiled, out int totalRecord)
        {
            var startRecord = pageSize * (pageIndex - 1);
            totalRecord = DataContext.Messages.Count();
            return this.DataContext.Messages.OrderByDescending(n => n.CreatedTime).Skip(startRecord).Take(pageSize);
        }
    }
}
